
from utils.vx.code2session import code2session
from utils.vx.crypt import WXBizDataCrypt
from app01.models import User


#把session中的authorized设置为true
def already_authorized(request):
    is_authorized = False
    if request.session.get('is_authorized'):
        is_authorized = True
    print('authorized status', is_authorized)
    return is_authorized

#通过认证后拿到open_id
def get_user(request):
    if not already_authorized(request):
        raise Exception('not autorized request')
    open_id = request.session.get('open_id')
    user = User.objects.get(open_id=open_id)
    return user

#实现c2s(appid,code)
def c2s(appid, code):
    return code2session(appid=appid, code=code)